package cn.com.cifi.mars.web.action.operateplan;


import java.util.List;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import cn.com.cifi.mars.bean.vo.returnPlan.ReturnCoefficientContentVo;
import cn.com.cifi.mars.bean.vo.returnPlan.ReturnPlanApprovalPreviewVo;
import cn.com.cifi.mars.common.base.BaseAction;
import cn.com.cifi.mars.common.bean.R;
import cn.com.cifi.mars.entity.ProjectReturnCoefficient;
import cn.com.cifi.mars.entity.ReturnCoefficientDetail;
import cn.com.cifi.mars.entity.common.IdmUser;
import cn.com.cifi.mars.service.ProjectReturnCoefficientService;
import cn.com.cifi.mars.service.ReturnCoefficientDetailService;


/**
 * @Description： 回款系数
 * @author：yyd
 * @date：2020年1月6日 上午10:49:14
 */
@RestController
public class ReturnCoefficientController extends BaseAction implements IReturnCoefficientController {
    @Autowired
    private ProjectReturnCoefficientService projectReturnCoefficientService;
    @Autowired
    private ReturnCoefficientDetailService returnCoefficientDetailService;
    
    //查询回款系数版本列表
    @Override
    public R getReturnVersionList(String apiVersion, String projectId, String versionType) {
        return ok(projectReturnCoefficientService.queryVersions(projectId, versionType));
    }

    //查询回款系数详情
    @Override
    public R returnCoefficientDetail(String apiVersion, String coefficientId) {
        return ok(returnCoefficientDetailService.queryByCoefficientId(coefficientId));
    }
    
    //修改审批状态仅供测试使用
    @Override
    public R updateState(String apiVersion, String versionId, String versionState) {
        projectReturnCoefficientService.updateState(versionId, versionState);
        return ok();
    }

    //自动生成实际版回款系数
    @Override
    public R createPractical(String apiVersion, String projectId) {
        returnCoefficientDetailService.createPracticalByProjectId(projectId);
        return ok();
    }

    //全量生成实际版回款系数
    @Override
    public R createAllPractical(String apiVersion) {
        returnCoefficientDetailService.createAllPractical();
        return ok();
    }

    //新建调整板回款系数
    @Override
    public R create(String apiVersion, String projectId) {
        IdmUser user = getOperator();
        ProjectReturnCoefficient returnCoefficient = projectReturnCoefficientService.create(projectId, user);
        return ok(returnCoefficient);
    }

    //删除版本
    @Override
    public R del(String apiVersion, String versionId) {
    	IdmUser user = getOperator();
        projectReturnCoefficientService.delete(versionId,user);
        return ok();
    }

    //审批校验
    @Override
    public R approvedCheck(String apiVersion, String versionId) {
        projectReturnCoefficientService.check(versionId);
        return ok();
    }

    //调整板回款系数编辑页面展示
    @Override
    public R queryDetail(String apiVersion, String coefficientId) {
        return ok(returnCoefficientDetailService.queryByCoefficientId(coefficientId));
    }

    //回款系数编辑页面保存
    @Override
    public R createSupplyBudgetVersion(String apiVersion, List<ReturnCoefficientDetail> param) {
        IdmUser user = getOperator();
        projectReturnCoefficientService.createSupplyBudgetVersion(param, user);
        return ok();
    }

    //查询回款系数审批预览PC
    @Override
    public R<String> getApprovalDetail(String apiVersion, String projectId, String examineId,String versionId) {
        IdmUser user = getOperator();
        return ok(projectReturnCoefficientService.getApprovalPreview(projectId, versionId,  user, examineId));
    }
    
    //查询回款系数审批预览app
    @Override
    public R<ReturnPlanApprovalPreviewVo> approvalPreviewApp(String apiVersion, String projectId, String examineId, String versionId) {
        IdmUser user = getOperator();
        return ok(projectReturnCoefficientService.getApprovalPreview(projectId, versionId,  user, examineId));
    }

    //提交到OA审批
    @Override
    public R<String> submitToOA(String apiVersion,ReturnCoefficientContentVo returnCoefficientContentVo) {
        IdmUser user = getOperator();
        return ok(projectReturnCoefficientService.getSubmitToOA(returnCoefficientContentVo,user));
    }
    
    //同步投资系统数据
    @Override
    public R getInvest(String apiVersion, String projectId) {
        projectReturnCoefficientService.syncInvestmentCoefficient(projectId);
        return ok();
    }

}

